import Axios from "axios";
import NProgress from "nprogress";
import 'nprogress/nprogress.css'

import { BASE_URL, TIME_OUT } from './config';

const instance = Axios.create({
    baseURL: BASE_URL,
    timeout: TIME_OUT,
    // headers: {},
    withCredentials: true
})
instance.interceptors.request.use(config => {
    NProgress.start()

    return config
}, err => {

})
instance.interceptors.response.use(config => {
    NProgress.done()
    return config.data;
}, err => {
    NProgress.done()
    console.log(err.response);
    if (err && err.response) {
        switch (err.response.status) {
            case 400:
                console.log('qingiu');
                break;
            case 401:
                console.log('未授权');
                break;
            default:
                break;
        }
    }
    return err
})
export default instance